package com.ds.infrastructure.hyperspace.console.entity.enums;

/**
 * @author: yaozhendong
 * @create: 2019-11-01 11:38
 **/

public interface TbNodeMetricsEnum {
    /**
     * TEMP_TYPE类型:1(ONE);2(TWO)
     */
    enum METRICS_KEY {
        HYPERSPACE_REQUESTS_TOTAL("hyperspace_requests_total", "hyperspace_requests_total[Counter]", MetricsAggregateFunctionEnum.SUBTRACTION),
        HYPERSPACE_REQUEST_SECONDS_BUCKET("hyperspace_request_seconds_bucket", "hyperspace_request_seconds_bucket[Histogram]", MetricsAggregateFunctionEnum.SUBTRACTION),
        HYPERSPACE_REQUEST_SECONDS_SUM("hyperspace_request_seconds_sum", "hyperspace_request_seconds_sum[]", MetricsAggregateFunctionEnum.SUBTRACTION),
        HYPERSPACE_REQUEST_SECONDS_COUNT("hyperspace_request_seconds_count", "hyperspace_request_seconds_count[Histogram]", MetricsAggregateFunctionEnum.SUBTRACTION),
        HYPERSPACE_REQUESTS_PENDING("hyperspace_requests_pending", "hyperspace_requests_pending[Gauge]", MetricsAggregateFunctionEnum.SAME),
        HYPERSPACE_CONNECTIONS("hyperspace_connections", "hyperspace_connections[Gauge]", MetricsAggregateFunctionEnum.SAME),
        HYPERSPACE_PAYLOAD_BYTES("hyperspace_payload_bytes", "hyperspace_payload_bytes[Counter]", MetricsAggregateFunctionEnum.SUBTRACTION),
        HYPERSPACE_ERRORS_TOTAL("hyperspace_errors_total", "hyperspace_errors_total[Counter]", MetricsAggregateFunctionEnum.SUBTRACTION),
        HYPERSPACE_TARGET_NODE_STATUS("hyperspace_target_node_status", "hyperspace_target_node_status[Gauge]", MetricsAggregateFunctionEnum.SAME);

        public final String key;
        private final String desc;
        public final MetricsAggregateFunctionEnum aggregateFunction;

        METRICS_KEY(String key, String desc, MetricsAggregateFunctionEnum aggregateFunction) {
            this.key = key;
            this.desc = desc;
            this.aggregateFunction = aggregateFunction;
        }

        public static METRICS_KEY toEnum(String key) {
            for (METRICS_KEY item : METRICS_KEY.values()) {
                if (item.key.equals(key)) {
                    return item;
                }
            }
            return null;
        }
    }

    enum ENDPOINT_TYPE_TAG {
        GATEWAY("gateway", "gateway"),
        TARGET("target", "target");

        public final String key;
        private final String desc;

        ENDPOINT_TYPE_TAG(String key, String desc) {
            this.key = key;
            this.desc = desc;
        }
    }

    enum HYPERSPACE_REQUEST_SECONDS_BUCKET_LE_TAG {
        LE01("0.1", "0.1", 1),
        LE05("0.5", "0.5", 2),
        LE10("1.0", "1.0", 3),
        LE50("5.0", "0.1", 4),
        LE_INF("+Inf", "+Inf", 5);

        public final String key;
        private final String desc;
        //顺序
        private final Integer order;

        HYPERSPACE_REQUEST_SECONDS_BUCKET_LE_TAG(String key, String desc, int order) {
            this.key = key;
            this.desc = desc;
            this.order = order;
        }

        public static HYPERSPACE_REQUEST_SECONDS_BUCKET_LE_TAG getNextLeTag(String key) {
            for (HYPERSPACE_REQUEST_SECONDS_BUCKET_LE_TAG item : HYPERSPACE_REQUEST_SECONDS_BUCKET_LE_TAG.values()) {
                if (item.key.equals(key)) {
                    return toEnum(item.order - 1);
                }
            }
            return null;
        }

        public static HYPERSPACE_REQUEST_SECONDS_BUCKET_LE_TAG toEnum(int order) {
            for (HYPERSPACE_REQUEST_SECONDS_BUCKET_LE_TAG item : HYPERSPACE_REQUEST_SECONDS_BUCKET_LE_TAG.values()) {
                if (item.order.equals(order)) {
                    return item;
                }
            }
            return null;
        }
    }
}
